#!/bin/bash

source /home/shell/util.sh



function backup () {
    gitlab-rake gitlab:backup:create
    cp -r /etc/gitlab/gitlab.rb /var/opt/gitlab/backups/gitlab.rb
    cp -r /etc/gitlab/gitlab-secrets.json /var/opt/gitlab/backups/gitlab-secrets.json
}

function backup_list(){
    printInfo "====================gitlab backup===================="
    ls -lSh /var/opt/gitlab/backups
    printInfo "====================gitlab backup===================="
}

function restore () {
    printInfo "备份列表"
    ls /var/opt/gitlab/backups|grep "gitlab_backup.tar"|perl -pe "s/(.*)_gitlab_backup\.tar/\1/g"
    read -p "请输入恢复的版本：" backup_version
gitlab-rake gitlab:backup:restore BACKUP=${backup_version}<<EOF
yes
yes
EOF
    cp -r /var/opt/gitlab/backups/gitlab.rb /etc/gitlab/gitlab.rb
    cp -r /var/opt/gitlab/backups/gitlab-secrets.json /etc/gitlab/gitlab-secrets.json
}

function update_backup () {
    rm -rf /var/opt/gitlab/backups/*
    backup
}


$1